package com.powernode.springmvc.controller;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: 曾铖坚
 * @Date: 2024/9/29 15:48
 * @Version: 1.0.0
 */
@Controller
public class ApplicationScopeTestController {
    @RequestMapping("/testApplicationScope")
    public String testApplicationScope(HttpServletRequest request){
        // 将数据存储到Application域对象中
        // 获取application对象，实际上是要获取ServletContext对象。
        // 怎么样获取ServletContext对象，通过request，通过session都可以获取
        ServletContext application = request.getServletContext();
        application.setAttribute("testApplicationScope","在SpringMVC框架中使用原生的Servlet API实现application域数据共享");
        return "ok";
    }
}
